package com.wenda.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wenda.bean.ThesisBean;
import com.wenda.entity.User;
import com.wenda.service.SearchService;

@Controller
public class SearchController {
	@Autowired
	SearchService searchService;
	
	/**
	 * 查询往届论题
	 * @param title
	 * @return
	 */
	@RequestMapping("/search/previous")
	public String searchPrevious(String title,HttpServletRequest request) {
		
		if(title.trim().equals("") || title == null) {
			return "user/previous_topic";
		}
		//根据用户所属院系查询论题索引库
		User user = (User) request.getSession().getAttribute("user");
		try {
			List<ThesisBean> result = searchService.query(title,user.getCollegeId(),false);
			request.setAttribute("thesisBeans", result);
			return "user/previous_topic";
		} catch (Exception e) {
			e.printStackTrace();
			return "user/previous_topic";
		}
	}
	@RequestMapping("/search/present")
	public String searchPresent(String title,HttpServletRequest request) {
		
		if(title == null || title.trim().equals("")) {
			return "user/present_topic";
		}
		//根据用户所属院系查询论题索引库
		User user = (User) request.getSession().getAttribute("user");
		try {
			List<ThesisBean> result = searchService.query(title,user.getCollegeId(),true);
			request.setAttribute("thesisBeans", result);
			return "user/present_topic";
		} catch (Exception e) {
			e.printStackTrace();
			return "user/present_topic";
		}
	}
}
